/**
 *    ------------ ipha console 一些输出预制  ------
 */
namespace iConsole {
    // 设置控制台输出的样式
    // 您可以使用该指令将 CSS 样式应用于控制台输出：%c
    // 指令之前的文本不会受到影响，但指令之后的文本将使用参数中的 CSS 声明进行样式设置。
    // console.log("This is %cMy stylish message", "color: yellow; font-style: italic; background-color: blue;padding: 2px");

    export function log_yellow(...data: any[]): void {
        const style: string = "color: #ffa631";
        log(style,data);
    }
    export function log_yellow_bg_orange(...data: any[]): void {
        const style: string = "color: #FAFC7C; background-color: #F76C24; padding: 2px 5px";
        log(style,data);
    }

    export function log_red(...data: any[]): void {
        const style: string = "color: #f47983";
        log(style,data);
    }
    export function log_red_bg_yellow(...data: any[]): void {
        const style: string = "color: #EB2424; background-color: #FFD356; padding: 2px 5px";
        log(style,data);
    }

    export function log_blue(...data: any[]): void {
        const style: string = "color: #065279";
        log(style,data);
    }
    export function log_blue_bg_zangQing(...data: any[]): void {
        const style: string = "color: #70f3ff; background-color: #2e4e7e; padding: 2px 5px";
        log(style, data);
    }

    export function log_green(...data: any[]): void {
        const style: string = "color: #21a675";
        log(style,data);
    }
    export function log_green_bg_yingBai(...data: any[]): void {
        const style: string = "color: #16a951; background-color: #e3f9fd; padding: 2px 5px";
        log(style,data);
    }

    export function log_purple(...data: any[]): void {
        const style: string = "color: #cca4e3";
        log(style,data);
    }
    export function log_purple_bg_yellow(...data: any[]): void {
        const style: string = "color: #DD91F2; background-color: #FCF4C1; padding: 2px 5px";
        log(style, data);
    }
}

function log(style: string, data: any[]) {
    let str: string = "%c";
    let dataList: any[][] = [];
    let dLIdx: number = 0;

    dataList[dLIdx] = [];

    for (const elem of data) {
        if (typeof elem == "string") {
            if (dataList[dLIdx].length > 0) {
                dataList[dLIdx][0] = dataList[dLIdx][0] + elem;
            } else {
                dataList[dLIdx][0] = str + elem;
            }
            // console.log(dLIdx, dataList[dLIdx]);
        } else {
            if (dataList[dLIdx].length > 0) {
                dataList[dLIdx][1] = style;
                dLIdx++;
                dataList[dLIdx] = [];
            }
            dataList[dLIdx].push(elem);
            // console.log(dLIdx, dataList[dLIdx]);
            dLIdx++;
            dataList[dLIdx] = [];
        }
    }

    if (typeof dataList[dLIdx][0] == "string") {
        dataList[dLIdx][1] = style;
    }

    for (let i = 0; i < dataList.length; i++) {
        const dataL = dataList[i];
        console.log(...dataL);
    }
}

export default iConsole;